package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.commons.entity.SysDicType;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.SysDicTypeService;
import com.gzxw.mogublog.xo.vo.SysDictTypeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/sysDicType")
public class SysDicTypeController {

    @Autowired
    private SysDicTypeService sysDicTypeService;

    @PostMapping("/getList")
    public R getList(@RequestBody SysDictTypeVO sysDictTypeVO) {

        IPage<SysDicType> pageList = sysDicTypeService.getList(sysDictTypeVO);
        HashMap<String, Object> map = new HashMap<>();
        map.put("records", pageList.getRecords());
        map.put("total", pageList.getTotal());
        map.put("size", pageList.getSize());
        map.put("current", pageList.getCurrent());
        return R.success("返回成功",map);
    }

    @PostMapping("/addSysDictType")
    public R add(@RequestBody SysDictTypeVO sysDictTypeVO) {

        String message = sysDicTypeService.addSysDictType(sysDictTypeVO);

        return R.success("200",message);
    }

    @PostMapping("/edit")
    public R edit(@RequestBody SysDictTypeVO sysDictTypeVO) {

        String message = sysDicTypeService.editSysDictType(sysDictTypeVO);

        return R.success("200",message);
    }

    @PostMapping("/deleteBatch")
    public R delete(@RequestBody List<SysDictTypeVO> sysDictTypeVoList) {

       String message = sysDicTypeService.deleteBatchSysDictType(sysDictTypeVoList);

       return R.success("200",message);
    }
}
